from distributed_lock import DistributedLock
import time

# 创建或获取分布式锁实例
lock = DistributedLock("localhost", 6379, "my_lock", 10)

if lock.acquire_lock():
    try:
        # 在获得锁之后执行需要保护的代码块
        print("Lock acquired. Performing critical section.")
        time.sleep(5)  # 模拟耗时操作
    finally:
        lock.release_lock()
        print("Lock released.")
else:
    print("Failed to acquire lock.")